package com.gxa.modules.service.impl;

import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.RegionMapper;
import com.gxa.modules.pojo.Region;
import com.gxa.modules.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class RegionServiceImpl implements RegionService {
    @Autowired(required = false)
    private RegionMapper regionMapper;
    @Override
    public ResultVo queryRegionList(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> regionMap=regionMapper.queryRegionList(param1,param2);
//        Integer result1=regionMapper.queryTotalShop();
//        Integer result2=regionMapper.queryTotalUser();
//        Integer result3=regionMapper.queryTotalMember();
        List<Map> result4=regionMapper.queryTotalDays();
        List list=new ArrayList();
        list.add(regionMap);
//        list.add(result1);
//        list.add(result2);
//        list.add(result3);
        list.add(result4);
        resultVo.setCode(200);
        resultVo.setData(list);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryByStatus1(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> regionMap=regionMapper.queryByStatus1(param1,param2);
        List<Map> result4=regionMapper.queryTotalDaysByStatus1();
        List list=new ArrayList();
        list.add(regionMap);
        list.add(result4);
        resultVo.setCode(200);
        resultVo.setData(list);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo queryStatus2(Integer currentPage, Integer pageSize) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> regionMap=regionMapper.queryByStatus2(param1,param2);
        List<Map> result4=regionMapper.queryTotalDaysByStatus2();
        List list=new ArrayList();
        list.add(regionMap);
        list.add(result4);
        resultVo.setCode(200);
        resultVo.setData(list);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo search(Integer currentPage, Integer pageSize, Integer status,String re_name) {
        ResultVo resultVo=new ResultVo();
        Integer param1=(currentPage-1)*pageSize;
        Integer param2=pageSize;
        List<Map> maps=regionMapper.search(param1,param2,status,re_name);
        resultVo.setCode(200);
        resultVo.setData(maps);
        resultVo.setMsg("查询成功");
        return resultVo;
    }

    @Override
    public ResultVo updateRegionStatus(Integer re_id,Integer re_status) {
        Integer result=regionMapper.updateRegionStatus(re_id,re_status);
        ResultVo resultVo=new ResultVo();
        if(result>0){
            resultVo.setCode(200);
            resultVo.setMsg("修改成功");
        }

        return resultVo;
    }

    @Override
    public ResultVo update(String oldPwd, String newPwd) {
        ResultVo resultVo=new ResultVo();
        Integer result=regionMapper.update(oldPwd,newPwd);
        if(result>0){
            resultVo.setCode(200);
            resultVo.setMsg("修改成功");
        }
        return resultVo;
    }

    @Override
    public ResultVo batchOpen(String[] ids) {
        ResultVo resultVo=new ResultVo();
        Integer result=0;
        if(ids.length > 0){
            for (String id : ids){
                result= regionMapper.batchOpen(id);
            }
        }
        if(result>0){
            resultVo.setCode(200);
            resultVo.setMsg("开启成功");
        }
        return resultVo;
    }

    @Override
    public ResultVo batchClose(String[] ids) {
        ResultVo resultVo=new ResultVo();
        Integer result=0;
        if(ids.length > 0){
            for (String id : ids){
                result= regionMapper.batchClose(id);
            }
        }
        if(result>0){
            resultVo.setCode(200);
            resultVo.setMsg("关闭成功");
        }
        return resultVo;
    }


}
